package org.srunpass.bitmap;

import java.util.Arrays;
import java.util.List;

import org.srunpass.bitmap.annotations.IndexField;
import org.srunpass.bitmap.repo.BitMapRepo;
import org.srunpass.bitmap.model.BitMapModel;
import org.srunpass.bitmap.repo.BitMapRepoWrapper;
import org.srunpass.bitmap.query.QueryWrapper;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 
 * 
 * @author srunpass
 * @version Id: ${NAME}, v 0.1 2025/6/30 09:12 srunpass Exp $
 */
public class Main {
    public static void main(String[] args) throws IllegalAccessException {
        User user1 = new User("张三", 13, "女", Arrays.asList("唱", "跳", "rap", "篮球"));
        User user2 = new User("李四", 14, "男", Arrays.asList("唱", "篮球"));
        User user3 = new User("王五", 13, "女", Arrays.asList("跳", "rap", "篮球"));
        User user4 = new User("赵六", 14, "男", Arrays.asList("唱", "跳"));
        List<User> users = Arrays.asList(user1, user2, user3, user4);

        BitMapRepo<User> userBitMapRepo = new BitMapRepo<>(User.class);
        for (User user : users) {
            userBitMapRepo.upsert(user);
        }

        QueryWrapper in = new QueryWrapper().in("like", "跳").and(o -> o.eq("sex", "男")).and(o -> o.eq("age", "13"))
            .or(o -> o.eq("name", "张三").or(o1 -> o1.and(o2 -> o2.eq("name", "王五"))));
        BitMapRepoWrapper<User> userBitMapRepoWrapper = new BitMapRepoWrapper<>(userBitMapRepo);
        List<User> query = userBitMapRepoWrapper.query(in);
        System.out.println("111");
    }

    @Data
    @AllArgsConstructor
    public static class User implements BitMapModel {

        @IndexField
        private String       name;

        @IndexField
        private int          age;

        @IndexField
        private String       sex;

        @IndexField(multiValue = true)
        private List<String> like;

        @Override
        public Object getId() {
            return name;
        }
    }
}